<?php

/**
 * ExtElementBase class file
 *
 * @author TrueSoftware B.V. (The Netherlands)
 * @link http://www.ext4yii.com
 * @copyright Copyright 2007-2010 TrueSoftwareB.V. all rights reserved.
 * @license http://www.ext4yii.com/license/
 *          EVALUATION VERSION - NOT FOR COMMERCIAL USE OR DISTRIBUTION.
 * @version 0.7.2
 */
abstract class ExtHtmlElementBase extends ExtWidget
{

    public function parseNode(ExtHTMLParserNode $node, ExtASTWalker $astwalker)
    {
        if (is_null($this->getTrimContent()))
            $this->setTrimContent(true);

        parent::parseNode($node, $astwalker);
        $this->setConfig('html', $this->extractBody($node));
        $this->setConfig('autoEl', $this->getTag());
        $node->outertext = '';
        $node->innertext = '';
        $node->shiftUp();
    }

    private function extractBody($node)
    {
        $body = $node->findPropertyByName('body');
        if (!is_null($body))
        {
            $this->checkInnerTypes($body);
            $html = $body->innertext();
            if ($this->getTrimContent() == true)
                $html = trim($html);
            $body->shiftUp();
            return $html;
        }
        else
            return null;
    }

    private function checkInnerTypes($node)
    {
        foreach ($node->nodes as $item)
        {
            if ($item->nodetype == HDOM_TYPE_EXTCOMP)
                throw new Exception(Ext4Yii::t('ext4yii',
                                'ExtHtmlElement can only contain HTML element tags. A component of type {class} was found.',
                                array('{class}' => get_class($item->extctl))
                ));
        }
    }

    //override
    public function configureClientIDs($registerID = true, $makeGlobal = true)
    {
        return parent::configureClientIDs($registerID, false);
    }

    //override
    public function renderConfig($asobject = true)
    {
        $this->deleteConfig('trimcontent');
        return parent::renderConfig($asobject);
    }

    public function createContainer(ExtHTMLParserNode $node)
    {
        return;
    }

}

?>
